package com.zy.explore.frm;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;

import javax.validation.constraints.Min;

/**
 * description 标准分页请求体
 *
 * @author ZY
 * @date 2021-05-05 18:03
 */
@ApiModel("标准分页请求体")
@Data
@NoArgsConstructor
@AllArgsConstructor
public class PageFrm implements PageableFrm {

    @ApiModelProperty(value = "页码，从 1 开始", dataType = "int", example = "1")
    @Min(value = 1, message = "页码不能小于 1")
    private int pageNum = 1;

    @ApiModelProperty(value = "每页大小", dataType = "int", example = "10")
    @Min(value = 1, message = "每页大小不能小于 1")
    private int pageSize = 10;

    @Override
    public Pageable toPageable() {
        return PageRequest.of(pageNum - 1, pageSize);
    }

    @Override
    public Pageable toPageable(Sort sort) {
        return PageRequest.of(pageNum - 1, pageSize, sort);
    }
}
